import fs from 'fs'
import path from 'path'
import { Dispatch } from '../reducers/types'
import { save_xml } from '../../file/file'

export const GET_FILE = 'GET_FILE'
export const CHANGE_FILE = 'CHANGE_FILE'

export const changefile = (name: string) => async (dispatch: Dispatch) => {
  const data = await fs.promises.readFile(path.join(save_xml, `${name}.xml`), 'utf-8')
  dispatch({ type: CHANGE_FILE, data: { value: data, name } })
}